__author__ = 'lill'
#coding: utf-8

import smtplib
from email.mime.text import MIMEText

mailto_list = ['123456@qq.com']    #收件人(列表)
mail_host = "smtp.qq.com"            #使用的邮箱的smtp服务器地址
mail_user = "789654@qq.com"       #用户名
mail_password = "12345678"    #密码
mail_postfix = "qq.com"              #邮箱的后缀

def send_mail(to_list, sub, content):
    me = "lill" + "<"+ mail_user + ">"
    msg = MIMEText(content, _subtype='plain', _charset='gb2312')
    msg['Subject'] = sub
    msg['From'] = me
    msg['To'] = ";".join(to_list)   #将收件人列表以‘；’分隔

    try:
        server = smtplib.SMTP(mail_host, 25)

        #可以用下面代替
        '''server = smtplib.SMTP(mail_host, 25)
        #server.connect(mail_host)             #连接服务器'''

        #server.set_debuglevel(1) #打印调试信息
        server.login(mail_user, mail_password)  #登录操作
        server.sendmail(me, to_list, msg.as_string())
        server.quit()
        return True

    except Exception, e:
        print str(e)
        return False

'''
#测试邮件发送
send_info = u'你好 python! smtp test.'
if send_mail(mailto_list, "python", send_info) == True: #邮件主题和邮件内容
    print ("success!")
else:
    print ("failed!")'''
